package com.fsai.cms.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger配置
 * 
 * @author 懒猴子CG
 * @date 2020/06/05 21:27
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

	@Value("${swagger.host:}")
	private String host;
	@Value("${swagger.title:}")
	private String title;
	@Value("${project.version:}")
	private String version;

	private ApiInfo apiInfo(String name, String description, String version) {
		ApiInfo apiInfo = new ApiInfoBuilder()//
				.title(name)//
				.description(description)//
				.version(version)//
				.contact(new Contact("Jaffe", "http://www.iuwms.com", "JaffeHe@foxmail.com"))//
				.build();
		return apiInfo;
	}

	@Bean
	public Docket sysApi() {
		return new Docket(DocumentationType.SWAGGER_2)//
				.select()//
				.apis(RequestHandlerSelectors.basePackage("com.fsai.cms.controller.cms"))//路径
				//				.paths(PathSelectors.ant("/apisys/**"))//
				.paths(PathSelectors.any())//
				.build().groupName("CMS-站点前台API")//
				.pathMapping("/")//
				.apiInfo(apiInfo("CMS-系统接口", "该文档主要针对系统API", version));
	}

	@Bean
	public Docket bizApi() {
		return new Docket(DocumentationType.SWAGGER_2)//
				.select()//
				.apis(RequestHandlerSelectors.basePackage("com.fsai.cms.controller.admin"))//路径
				.paths(PathSelectors.any())//
				//				.paths(PathSelectors.any())//
				.build().groupName("CMS-站点后台API")//
				.pathMapping("/")//
				.apiInfo(apiInfo("CMS-系统后台接口", "该文档主要针对系统后台API", version));
	}

}